<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Elasticsearch Watchers 深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        pre {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            margin-top: -8px;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
            padding-bottom: 30px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 0;
            bottom: 0;
            width: 2px;
            background: #e5e7eb;
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 6px;
            top: 8px;
            width: 10px;
            height: 10px;
            background: #667eea;
            border-radius: 50%;
        }
        
        .timeline-item:last-child::before {
            display: none;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    Elasticsearch Watchers
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    构建智能监控与告警系统的核心引擎
                </p>
                <div class="flex justify-center space-x-4">
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3">
                        <i class="fas fa-eye mr-2"></i>
                        实时监控
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3">
                        <i class="fas fa-bell mr-2"></i>
                        智能告警
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3">
                        <i class="fas fa-cogs mr-2"></i>
                        自动响应
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <section class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Elasticsearch（ES）中，Watchers是用于监控集群状态、索引性能及数据变化的重要工具。通过Watchers，用户可以设置条件，当条件满足时触发告警和相应的行动。这一功能在构建高可用、高性能的搜索服务中尤为重要。
            </p>
        </section>

        <!-- Concept Section -->
        <section class="mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-lightbulb text-purple-600 mr-3"></i>
                Watchers的概念
            </h2>
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <p class="text-lg leading-relaxed text-gray-700">
                    Watchers是Elasticsearch中的一种功能，允许用户定义监控任务（称为"watch"），这些任务可以定期检查特定条件。如果条件满足，Watchers可以执行指定的操作，比如发送电子邮件、触发Webhook、记录日志等。
                </p>
                <div class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-6">
                    <div class="text-center">
                        <div class="feature-icon mx-auto">
                            <i class="fas fa-clock"></i>
                        </div>
                        <h4 class="font-semibold text-gray-800 mb-2">定期检查</h4>
                        <p class="text-gray-600">按照设定的时间间隔自动执行监控任务</p>
                    </div>
                    <div class="text-center">
                        <div class="feature-icon mx-auto">
                            <i class="fas fa-filter"></i>
                        </div>
                        <h4 class="font-semibold text-gray-800 mb-2">条件判断</h4>
                        <p class="text-gray-600">智能判断监控数据是否满足预设条件</p>
                    </div>
                    <div class="text-center">
                        <div class="feature-icon mx-auto">
                            <i class="fas fa-bolt"></i>
                        </div>
                        <h4 class="font-semibold text-gray-800 mb-2">自动响应</h4>
                        <p class="text-gray-600">条件满足时自动执行预定义的操作</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Working Principle -->
        <section class="mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-cog text-purple-600 mr-3"></i>
                Watchers的工作原理
            </h2>
            
            <!-- Workflow Diagram -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
                <div class="mermaid">
                    graph LR
                        A[创建Watch] --> B[设置触发器]
                        B --> C[定义输入源]
                        C --> D[配置条件]
                        D --> E[指定动作]
                        E --> F[定期执行]
                        F --> G{条件判断}
                        G -->|满足| H[执行动作]
                        G -->|不满足| F
                        H --> I[记录日志]
                        I --> F
                </div>
            </div>

            <!-- Create Watch -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-6 card-hover">
                <h3 class="text-2xl font-bold mb-4 text-gray-800">
                    <span class="text-gradient">2.1</span> 创建Watch
                </h3>
                <p class="text-lg text-gray-700 mb-6">
                    用户通过REST API或Kibana界面创建Watch。在创建过程中，需要定义以下几个关键部分：
                </p>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div class="bg-purple-50 rounded-lg p-6">
                        <h4 class="font-bold text-purple-800 mb-2">
                            <i class="fas fa-stopwatch mr-2"></i>触发条件（Trigger）
                        </h4>
                        <p class="text-gray-700">指定Watch的执行频率。例如，可以设置为每分钟检查一次。</p>
                    </div>
                    <div class="bg-blue-50 rounded-lg p-6">
                        <h4 class="font-bold text-blue-800 mb-2">
                            <i class="fas fa-database mr-2"></i>输入（Input）
                        </h4>
                        <p class="text-gray-700">定义Watch需要监控的数据来源，如查询特定索引的文档、聚合查询结果等。</p>
                    </div>
                    <div class="bg-green-50 rounded-lg p-6">
                        <h4 class="font-bold text-green-800 mb-2">
                            <i class="fas fa-check-circle mr-2"></i>条件（Condition）
                        </h4>
                        <p class="text-gray-700">指定何时触发告警，例如当某个聚合结果超过某个阈值。</p>
                    </div>
                    <div class="bg-red-50 rounded-lg p-6">
                        <h4 class="font-bold text-red-800 mb-2">
                            <i class="fas fa-play-circle mr-2"></i>动作（Actions）
                        </h4>
                        <p class="text-gray-700">定义满足条件后要执行的操作，如发送邮件、发送HTTP请求等。</p>
                    </div>
                </div>
            </div>

            <!-- Trigger and Execute -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <h3 class="text-2xl font-bold mb-4 text-gray-800">
                    <span class="text-gradient">2.2</span> 触发和执行
                </h3>
                <p class="text-lg text-gray-700 mb-6">
                    一旦Watch被创建，Elasticsearch会根据设定的触发频率定期检查指定的输入数据。每次执行Watch时，会进行以下操作：
                </p>
                <div class="timeline">
                    <div class="timeline-item">
                        <h4 class="font-bold text-gray-800 mb-2">数据采集</h4>
                        <p class="text-gray-600">根据定义的输入，从指定的索引中获取数据。</p>
                    </div>
                    <div class="timeline-item">
                        <h4 class="font-bold text-gray-800 mb-2">条件判断</h4>
                        <p class="text-gray-600">使用条件模块判断获取的数据是否满足触发条件。</p>
                    </div>
                    <div class="timeline-item">
                        <h4 class="font-bold text-gray-800 mb-2">执行动作</h4>
                        <p class="text-gray-600">如果条件满足，系统将执行指定的动作。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Components -->
        <section class="mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-puzzle-piece text-purple-600 mr-3"></i>
                Watchers的组成部分
            </h2>

            <!-- Trigger -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-6 card-hover">
                <h3 class="text-2xl font-bold mb-4 text-gray-800">
                    <span class="text-gradient">3.1</span> 触发器（Trigger）
                </h3>
                <p class="text-lg text-gray-700 mb-4">
                    触发器指定Watch执行的频率，可以是固定的时间间隔（如每分钟、每小时等），也可以使用Cron表达式自定义时间计划。
                </p>
                <pre><code>{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  }
}</code></pre>
            </div>

            <!-- Input -->
            <div class="bg-white